package org.me.runaway;

import android.content.Context;
import android.database.Cursor;
import java.util.ArrayList;


public class AutoCompleteList {
    private ArrayList<String> names;

    public AutoCompleteList(){
        names = new ArrayList<String>();
    }

    public void addName(String name){
        names.add(name);
    }

    public void deleteName(String name){
        names.remove(name);
    }

    public int getSize(){
        return names.size();
    }

    public String[] toArrayString(){
        String str [] = new String [names.size()];
        names.toArray(str);
        return str;
    }

    public String[] getAll(Context ctx){
        DB_Adapter db = new DB_Adapter(ctx);
        db.open();
        Cursor cs = db.getAllPlaces();
        if (cs != null){
            cs.moveToFirst();
            String[] array = new String[cs.getCount()];
            for (int i=0; i < cs.getCount(); i++){
                array[i] = cs.getString(cs.getColumnIndex(Place.KEY_NAME));
                cs.moveToNext();
            }
            db.close();
            return array;
        }
        return null;
    }
}
